package com.qianfeng.yime.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.qianfeng.yime.*;
import com.qianfeng.yime.model.User;
import com.qianfeng.yime.util.CurrentSingleton;

/**
 * Created by Fcy on 2015/3/10.
 */
public class FindFragment extends Fragment implements View.OnClickListener {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View ret = inflater.inflate(R.layout.fragment_find, container, false);

        ret.findViewById(R.id.find__hot_job).setOnClickListener(this);
        ret.findViewById(R.id.find__recommended_job).setOnClickListener(this);
        ret.findViewById(R.id.find__member_benefits).setOnClickListener(this);

        return ret;
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        Context context = getActivity();
        switch (v.getId()) {
            case R.id.find__hot_job: // 热门职业
                intent = new Intent(context, HotJobActivity.class);
                break;
            case R.id.find__recommended_job: // 推荐职业
                intent = new Intent(context, RecommendJobActivity.class);
                break;
            case R.id.find__member_benefits: // 积分
                // TODO 判断是否登录
                CurrentSingleton singleton = CurrentSingleton.getInstance();
                User user = singleton.getUser();
                if (user == null) {
                    // TODO 登录
                    intent = new Intent(getActivity(), UserLoginActivity.class);
                    // 获取要跳转的Activity的类名，包括包名：com.qianfeng.yime.fragment.
                    intent.putExtra(Constants.INTENT_CLASS_NAME, ScoreActivity.class.getName());
                } else {
                    intent = new Intent(getActivity(), ScoreActivity.class);
                }
                break;
        }
        if (intent != null) {
            startActivity(intent);
        }
    }
}